-
Notifications
You must be signed in to change notification settings - Fork 0
139. Word Break #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
139. Word Break #39
Conversation
| if (words.contains(word)) { | ||
| breakable_indexes.push_back(index); | ||
| break; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
自分だったら以下のような変数名にします。
for (int end = 1; end <= s.size(); ++end) {
for (int start : breakable_indexes) {
string_view sub_str = s_view.substr(start, end - start);
if (words.contains(sub_str)) {| while (!index_to_check.empty()) { | ||
| int index = index_to_check.front(); | ||
| index_to_check.pop(); | ||
| for (int i = 1; i <= s.size() - index; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここの i は word_length もしくは sub_str_length かなと思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
たしかにそちらのほうがだいぶ分かりやすくなりますね!
| public: | ||
| bool wordBreak(string s, vector<string>& wordDict) { | ||
| unordered_set<string> words(wordDict.begin(), wordDict.end()); | ||
| unordered_set<int> visited; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
型で分かると言えば分かるのですが、 visited_indices の命名とかの方がよりわかりやすいと思います。
問題文
https://leetcode.com/problems/word-break/description/